<template>
    <div>
        <!--顶部滑动条区域-->
        <div id="slider" class="mui-slider">
            <div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
                <div class="mui-scroll">
                    <a :class="['mui-control-item', item.id===0 ? 'mui-active':'']"
                       v-for="item in catalogs" :key="item.id" @tap="getAllList(item.id)">
                        {{item.catalog}}
                    </a>
                </div>
            </div>
        </div>
       <!--//中间图片区域-->
        <ul class="bookInfo">
            <router-link :to="'/home/bookinfo/'+item.sub1"  v-for="item in list" :key="item.sub1" tag="li">
                <img src="" alt="" v-lazy="item.img">
                <div class="info">
                    <h1 class="info-title">{{item.sub1}}</h1>
                    <div class="info-body">{{item.sub2}}</div>
                </div>
            </router-link>
        </ul>

    </div>
</template>

<script>
    import mui from '../../lib/mui/js/mui.min.js'

    export default {
        name: "booklist",
        data(){
            return {
                catalogs:[],
                list:[],
            }
        },
        methods:{
            getAllCategory(){
                this.$axios.get('/catalog?key=ee22a1e78b90506df4c51628ccfae9f6&dtype=json').then(res=>{
                    res.data.result.unshift({id:0,catalog:'全部'});     //手动添加全部图书的分类
                    this.catalogs= res.data.result
                    console.log(this.catalogs)
                })
            },
            //根据id获取书本列表
            getAllList(cateId){
                if(cateId==0){
                    cateId=246
                }
                this.$axios.get('/query?key=ee22a1e78b90506df4c51628ccfae9f6&rn=10&rn=10&catalog_id='+cateId)
                    .then(res=>{
                        console.log(res)
                        this.list=res.data.result.data
                        for(var i=0;i<this.list.length;i++){
                            this.list[i].unshift({id:cateId})
                            console.log(this.list[i].id)
                        }
                    })
            }
        },
        created(){
            this.getAllCategory();
                //默认进入页面，就主动请求所有图书列表的数据
            this.getAllList(246)
        },
        mounted() {
            mui('.mui-scroll-wrapper').scroll({
                deceleration:0.0005
            });
        },
    }
</script>

<style scoped>
    *{
         touch-action: pan-y;
     }

    .bookInfo{
        margin: 0;
        padding: 10px 10px 0;
    }
    .bookInfo li {
        list-style-type: none;
        background-color: #ccc;
        text-align: center;
        margin-bottom: 10px;
        box-shadow: 0 0 9px #999;
        position: relative;
    }
    .bookInfo li img{
        width: 100%;
        vertical-align: middle;
    }
    .bookInfo li img[lazy="loading"]{
        width: 40px;
        height: 300px;
        margin: auto;
    }
    .info {
        color:white;
        text-align: left;
        position: absolute;
        bottom: 0;
        background-color: rgba(0,0,0,0.4);
        max-height: 84px;
    }
    .info .info-title {
        font-size:14px;
    }
    .info .info-body{
        font-size:13px;
    }
</style>